<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 26] 26.3 java.lang.reflect.Field (JDK 1.1)</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:28:54 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch26_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 26<br>The java.lang.reflect Package</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch26_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-26-SECT-3">26.3 java.lang.reflect.Field (JDK 1.1)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-26-SECT-3.1"></A></h3>
</DIV>

<P CLASS=para>
This class represents a field of a class.  Instances of
<tt CLASS=literal>Field</tt> are obtained by calling the <tt CLASS=literal>getField()</tt>
and related methods of <tt CLASS=literal>java.lang.Class</tt>.
<tt CLASS=literal>Field</tt> implements the <tt CLASS=literal>Member</tt> interface, so
once you have obtained a <tt CLASS=literal>Field</tt> object, you can use
<tt CLASS=literal>getName()</tt>, <tt CLASS=literal>getModifiers()</tt>, and
<tt CLASS=literal>getDeclaringClass()</tt> to determine the name,
modifiers, and class of the field.  Additionally,
<tt CLASS=literal>getType()</tt> returns the type of the field.

<P CLASS=para>
The <tt CLASS=literal>set()</tt> method sets the value of the represented
field for a specified object to a given value.
(If the represented field is <tt CLASS=literal>static</tt>, then no object
need be specified for it to be set upon, of course.)  If the
field is of a primitive type, its value can be specified
using a wrapper object of type <tt CLASS=literal>Boolean</tt>,
<tt CLASS=literal>Integer</tt>, and so on, or it can be set using the
<tt CLASS=literal>setBoolean()</tt>, <tt CLASS=literal>setInt()</tt>, and related
methods.

<P CLASS=para>
Similarly, the <tt CLASS=literal>get()</tt> method queries the value of the
represented field for a specified object and returns the
field value as an <tt CLASS=literal>Object</tt>.  Various other methods
query the field value and return it as various primitive types.

<DIV CLASS=screen>
<P>
<PRE>
public final class <tt CLASS=literal>Field</tt> extends Object implements Member {
    // <tt CLASS=literal>No Constructor</tt>
    // <tt CLASS=literal>Public Instance Methods</tt>
            public boolean <tt CLASS=literal>equals</tt>(Object <tt CLASS=literal>obj</tt>);  //<tt CLASS=literal> Overrides Object</tt>
            public native Object <tt CLASS=literal>get</tt>(Object <tt CLASS=literal>obj</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native boolean <tt CLASS=literal>getBoolean</tt>(Object <tt CLASS=literal>obj</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native byte <tt CLASS=literal>getByte</tt>(Object <tt CLASS=literal>obj</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native char <tt CLASS=literal>getChar</tt>(Object <tt CLASS=literal>obj</tt>) throws IllegalArgumentException, IllegalAccessException;
            public Class <tt CLASS=literal>getDeclaringClass</tt>();  //<tt CLASS=literal> From Member</tt>
            public native double <tt CLASS=literal>getDouble</tt>(Object <tt CLASS=literal>obj</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native float <tt CLASS=literal>getFloat</tt>(Object <tt CLASS=literal>obj</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native int <tt CLASS=literal>getInt</tt>(Object <tt CLASS=literal>obj</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native long <tt CLASS=literal>getLong</tt>(Object <tt CLASS=literal>obj</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native int <tt CLASS=literal>getModifiers</tt>();  //<tt CLASS=literal> From Member</tt>
            public String <tt CLASS=literal>getName</tt>();  //<tt CLASS=literal> From Member</tt>
            public native short <tt CLASS=literal>getShort</tt>(Object <tt CLASS=literal>obj</tt>) throws IllegalArgumentException, IllegalAccessException;
            public Class <tt CLASS=literal>getType</tt>();
            public int <tt CLASS=literal>hashCode</tt>();  //<tt CLASS=literal> Overrides Object</tt>
            public native void <tt CLASS=literal>set</tt>(Object <tt CLASS=literal>obj</tt>, Object <tt CLASS=literal>value</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native void <tt CLASS=literal>setBoolean</tt>(Object <tt CLASS=literal>obj</tt>, boolean <tt CLASS=literal>z</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native void <tt CLASS=literal>setByte</tt>(Object <tt CLASS=literal>obj</tt>, byte <tt CLASS=literal>b</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native void <tt CLASS=literal>setChar</tt>(Object <tt CLASS=literal>obj</tt>, char <tt CLASS=literal>c</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native void <tt CLASS=literal>setDouble</tt>(Object <tt CLASS=literal>obj</tt>, double <tt CLASS=literal>d</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native void <tt CLASS=literal>setFloat</tt>(Object <tt CLASS=literal>obj</tt>, float <tt CLASS=literal>f</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native void <tt CLASS=literal>setInt</tt>(Object <tt CLASS=literal>obj</tt>, int <tt CLASS=literal>i</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native void <tt CLASS=literal>setLong</tt>(Object <tt CLASS=literal>obj</tt>, long <tt CLASS=literal>l</tt>) throws IllegalArgumentException, IllegalAccessException;
            public native void <tt CLASS=literal>setShort</tt>(Object <tt CLASS=literal>obj</tt>, short <tt CLASS=literal>s</tt>) throws IllegalArgumentException, IllegalAccessException;
            public String <tt CLASS=literal>toString</tt>();  //<tt CLASS=literal> Overrides Object</tt>
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-26-SECT-3.2">Returned By:</A></h3>

<P CLASS=para>
Class.getDeclaredField(), 
Class.getDeclaredFields(), 
Class.getField(), 
Class.getFields()

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch26_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch26_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.lang.reflect.Constructor (JDK 1.1)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java.lang.reflect.InvocationTargetException (JDK 1.1)</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
